package com.resys.server.controller.admin;

import com.resys.entity.po.User;
import com.resys.entity.query.UserQuery;
import com.resys.entity.vo.ResponseVO;
import com.resys.server.controller.ABaseController;
import com.resys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController("passAdminController")
@Slf4j
@RequestMapping("/admin/passAdmin")
@Api(tags = "管理员模块-审核通过管理员接口")
public class passAdminController extends ABaseController {
    @Resource
    private UserService userService;
    @ApiOperation("获取待审核的管理员列表")
    @GetMapping()
    public ResponseVO list() {
        UserQuery userQuery = new UserQuery();
        userQuery.setRole(0);
        userQuery.setAccountStatus(1);
        List<User> userList = userService.findListByParam(userQuery);
        return getSuccessResponseVO(userList);
    }
    @ApiOperation("审核通过管理员")
    @GetMapping("/pass")
    public ResponseVO pass(String userId) {
        User user = userService.getUserByUserId(userId);
        if(user == null) {
            return getServerErrorResponseVO("用户不存在");
        }
        user.setAccountStatus(0);
        userService.updateUserByUserId(user,userId);
        return getSuccessResponseVO("审核通过");
    }
    @ApiOperation("撤销管理员注册申请")
    @GetMapping("/del")
    public ResponseVO del(String userId) {
        userService.deleteUserByUserId(userId);
        return getSuccessResponseVO("撤销成功");
    }
}
